package hot.charr;

import java.util.List;

public class A151 {
    public static void main(String[] args) {
        A151 a=new A151();
        String s="the sky is blue";
        s=a.reverseWords(s);
        System.out.println(s);
    }
    public String reverseWords(String s) {
        char[] oldChar = s.toCharArray();
        char[] newChar=new char[s.length()+1];
        int i=s.length()-1;
        int index=0;
        while(i>=0){
            while(i>=0&&oldChar[i]==' ')i--;
            //右边界
            int r=i;
            //左边界
         while(i>=0&&oldChar[i]!=' ')i--;
         //添加到新数组
        for(int j=i+1;j<=r;j++){
            newChar[index++]=oldChar[j];
        }
newChar[index++]=' ';
        }
        return new String(newChar,0,newChar.length-1);
    }
}





